// JavaScript Document
/*
* JSCore contain necessary method for support OOP in javascript
*   Sources from  {inheritance}
*
*/

if(typeof JSCore === 'undefined' || !JSCore){
	var JSCore = {
		/**
		 * A function used to extend one class with another
		 * 
		 * @param {Object} subClass
		 * 		The inheriting class, or subclass
		 * @param {Object} baseClass
		 * 		The class from which to inherit
		 * @author http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm#Anchor-Introductio-24059		
		 */
		extend : function (subClass,superClass,overrides){
		 if (!superClass||!subClass) {
            throw new Error("extend failed, please check that " +
                            "all dependencies are included.");
        }
		 function inheritance() {}
		 
		 inheritance.prototype = superClass.prototype;

	     subClass.prototype = new inheritance();
		 subClass.prototype.constructor = subClass;

		  // for calling base constructor
         subClass.superclass = superClass.prototype;
		 subClass.superclass.constructor = superClass;
         
		},
		namespace : function(ns){
			var d = ns.split(".");
			var i,root,o = null;
			root = d[0] || {};
			eval('if (typeof ' + root + ' == "undefined"){' + root + ' = {};} o = ' + root + ';');
			for(i = 1; i < d.length;i++){				  
				  o[d[i]]=o[d[i]] || {};
                  o = o[d[i]];
			}
		}
		,
		parseJSON : function(data){
			return  eval('(' + data + ')');
		}
	}	
}

/**Test------- extend */
var Person = function(first,last){
	this.first = first;
	this.last = last;
	this.getFullName = function(){
		return this.first+this.last;
	}
}

var Manager = function(first, last, id, department){
	Manager.superclass.constructor.call(this, first, last, id);
	this.department = department;
}

JSCore.extend(Manager,Person);

var man = new Manager("Pradit","Rattanapongchinda","1","ECS");
//alert(man.getFullName());


/**Test------- namespace */
JSCore.namespace("com");
//alert(com);
JSCore.namespace("com.prog.task");
//alert(com.prog.task);